const app = getApp()
import {
  formatDate
} from '../utils/conmon'

Component({
  /**
   * 组件的属性列表
   */
  // [ {value:2,txt:'自定义',list:[
  //   {value:1,txt:'周一',isSelect:true},
  //   {value:2,txt:'周二',isSelect:false},
  //   {value:3,txt:'周三',isSelect:false},
  //   {value:4,txt:'周四',isSelect:false},
  //   {value:5,txt:'周五',isSelect:false},
  //   {value:6,txt:'周六',isSelect:false},
  //   {value:7,txt:'周日',isSelect:false},
  // ]

  /**
   * 组件的初始数据
   */
  data: {
    customData:[],
    onShow:false,
    businsType:0,//  businType==3 带标题，带下拉展示组件
    selectData:{},
  },

  /**
   * 组件的方法列表
   */
  methods: {


    onShowSingelAlert(customData,type){
      let dt ={
        customData:customData,
        onShow:true,
        businsType:type||0
      }
      if(type==3){
       dt.onShow= false
       dt.selectData = this.upSelectData(customData)
       
      }
      this.setData(dt)
    },

    upSelectData(data){
        for(let i=0;i<data.length;i++){
          let item = data[i];
          
          if(item.isSelect==true){
            console.log('@@@',JSON.stringify(data))
            return item
          }
        }
        return {}
    },

    didClickCheckInddex(envent){//点击标题选择
      
      var vt = envent.currentTarget.dataset;

      console.log(JSON.stringify(vt))
      var superIndex =vt.alphaBeta
      var currentIndex =vt.alphabeta

      var index = vt.index;

      var dataList=this.data.customData;
      for(var i=0;i<dataList.length;i++){
          var item  = dataList[i]

          if(item){

            for(var y=0;y<item.length;y++){
              var itemY = item[y];
              if(superIndex==i&&y==currentIndex){
                itemY.isSelect = true;
                if(itemY.list){
                  for(var x=0;x<itemY.list.length;x++){
                    var itemX = itemY.list[x];
                    if(superIndex==i&&y==currentIndex&&x==index){
                      itemX.isSelect = !itemX.isSelect;
      
                        
      
                    }
      
                  }
                 }

              }else{
                itemY.isSelect = false;

              }

            }
           }

      }

      this.setData({
        customData:dataList
      })


    },

    titleClick(envent){//标题回调
      
      var vt = envent.currentTarget.dataset.index;
      this.triggerEvent("titleDateIndex",vt)
    },

    onHideAlert(){
        this.setData({
          onShow:false
        })
    },
    actionSheetData(){//循环点击确定

      var dataList=this.data.customData;
      var data ={}
      for(var i=0;i<dataList.length;i++){
          var item  = dataList[i]

          if(item){

            for(var y=0;y<item.length;y++){
              var itemY = item[y];
              
              if(itemY.isSelect){
                data=itemY

                if(itemY.list){
                  // var list =[]
                  // for(var x=0;x<itemY.list.length;x++){
                  //   var itemX = itemY.list[x];
                  //   if(itemX.isSelect){
      
                  //     list.push(itemX)
      
                  //   }
      
                  // }

                  data.list =itemY.list
                 }

              }else{

              }

            }
           }

      }


      this.triggerEvent("actionSheetycle",data)
      this.onHideAlert();

    },
    didClick(e){
    
      let index = e.currentTarget.dataset.index;
      var data = this.data.customData[index];
      data.index =index

      this.triggerEvent("actionSheetIndex",data)
      this.onHideAlert();
    }
  

  }
})
